﻿Imports Microsoft.VisualBasic.ControlChars

Public Class frmTabVerticalCoordinate
    Public Shared sKdelim As String = CrLf
    Dim editnode As EditXML = New EditXML()

    Private Sub btnAddAltRes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddAltRes.Click
        Dim s1 As String = ""
        Dim s2 As String = numAltRes.Value.ToString
        Dim iPos As Integer = 0

        iPos = s2.IndexOf(".")
        If (iPos < 0) Then
            s2 += ".0" 'make sure the value is a real
        End If
        s1 = txtAltRes.Text 'retrieve current set of resolutions
        If (s1 = "") Then
            s1 = s2 'put new resolution into string
        Else
            s1 += sKdelim & s2 'add new resolution to string, with delimiter
        End If
        txtAltRes.Text = s1 'update the text box
    End Sub

    Private Sub btnClearAltRes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearAltRes.Click
        txtAltRes.Text = ""
        numAltRes.Value = 0
    End Sub

    Private Sub btnAddDepth_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddDepth.Click
        Dim s1 As String = ""
        Dim s2 As String = numDepthRes.Value.ToString
        Dim iPos As Integer = 0

        iPos = s2.IndexOf(".")
        If (iPos < 0) Then
            s2 += ".0" 'make sure the value is a real
        End If
        s1 = txtDepthRes.Text 'retrieve current set of resolutions
        If (s1 = "") Then
            s1 = s2 'put new resolution into string
        Else
            s1 += sKdelim & s2 'add new resolution to string, with delimiter
        End If
        txtDepthRes.Text = s1 'update the text box
    End Sub

    Private Sub btnClrDepthRes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClrDepthRes.Click
        txtDepthRes.Text = ""
        numDepthRes.Value = 0
    End Sub

    Private Sub frmTabVerticalCoordinate_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
        editXMLFile()
    End Sub
    Public Sub editXMLFile()
        editnode.Edit("/metadata/spref/vertdef/altsys/altdatum", cboxAltDatum.SelectedItem)
        editnode.Edit("/metadata/spref/vertdef/altsys/altunits", cboxAltUnits.SelectedItem)
        editnode.Edit("/metadata/spref/vertdef/altsys/altenc", cboxAltEncode.SelectedItem)
        editnode.Remove("/metadata/spref/vertdef/altsys", "altres")
        Dim items1() As String = txtAltRes.Text.Split(sKdelim)
        For i As Integer = items1.GetUpperBound(0) To 0 Step -1
            editnode.Add("/metadata/spref/vertdef/altsys", "/altdatum", "altres", items1(i).Trim())
        Next
        editnode.Edit("/metadata/spref/vertdef/depthsys/depthdn", cboxDepthDatum.SelectedItem)
        editnode.Edit("/metadata/spref/vertdef/depthsys/depthdu", cboxDepthUnits.SelectedItem)
        editnode.Edit("/metadata/spref/vertdef/depthsys/depthem", cboxDepthEncode.SelectedItem)
        editnode.Remove("/metadata/spref/vertdef/depthsys", "depthres")
        Dim items2() As String = txtDepthRes.Text.Split(sKdelim)
        For i As Integer = items1.GetUpperBound(0) To 0 Step -1
            editnode.Add("/metadata/spref/vertdef/depthsys", "/depthdn", "depthres", items2(i).Trim())
        Next
    End Sub

    Private Sub button_example_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_example.Click
        Dim helpForm As dialog_help = New dialog_help("VerticalCoordinate")
        helpForm.ShowDialog()
    End Sub
End Class